﻿#region
/*******************************************************************************
** File Name:		    CashTypeService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using EWineShop.Service.Contracts;
using EWineShop.Service.Model;
using EWineShop.IBatisRepository;
using EWineShop.Respository;
using System.Data;
using EWineShop.Entity;

namespace EWineShop.Service
{
    public class CashTypeService : ICashTypeService
    {
		 ICashType cashType = new CashTypeRepository();
		 
		 #region  Auto Generation
		 

		public void UpdateByCashTypeID (CashTypeModel model)
		{
			ECashType entity = ConvertModelToEntity(model);

            cashType.UpdateByCashTypeID(entity);

		}

		public void DeleteByCashTypeID (System.Int64 cashTypeID)
		{
		
            cashType.DeleteByCashTypeID(cashTypeID);

		}
		 
        public CashTypeModel GetByCashTypeID (System.Int64 cashTypeID)
        {
        
			ECashType entity = cashType.GetByCashTypeID(cashTypeID);
			
            CashTypeModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<CashTypeModel> GetAll ()
		{
			IList<ECashType> entity = cashType.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<CashTypeModel> list = new List<CashTypeModel>();

            foreach (var item in entity)
            {
                CashTypeModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private CashTypeModel ConvertEntityToModel(ECashType entity)
		{
			if (entity == null)
            {
                return null;
            }
			CashTypeModel model = new CashTypeModel();
                        model.CashTypeID = entity.CashTypeID;
                        model.Code = entity.Code;
                        model.Name = entity.Name;
                        model.Rate = entity.Rate;
                        model.Remark = entity.Remark;
                        model.CreateTime = entity.CreateTime;
                        model.UpdateTime = entity.UpdateTime;
                        return model;
		}
		
		private ECashType ConvertModelToEntity(CashTypeModel model)
		{
			if (model == null)
            {
                return null;
            }
			ECashType entity = new ECashType();
                        entity.CashTypeID = model.CashTypeID;
                        entity.Code = model.Code;
                        entity.Name = model.Name;
                        entity.Rate = model.Rate;
                        entity.Remark = model.Remark;
                        entity.CreateTime = model.CreateTime;
                        entity.UpdateTime = model.UpdateTime;
                        return entity;
		}
		
		
		
		#endregion
    }
}